import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { GlobalSkin } from "../../../component/skin/GlobalSkin";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { OpenRechargeInfo } from "./OpenRechargeInfo";
import { ItemData } from "../../resource/info/ItemData";
import { OpenRechargeType } from "./OpenRechargeType";
import { Language } from "../../../../extend/language/Language";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { TOpenRechargeGiftBag } from "../../../../Message/Db/Tables/TOpenRechargeGiftBag";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class OpenRechargeRenderer
    
    export  class OpenRechargeRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        public get itemCode(): int
        {
            if (this._info) 
            {
                return this._info.itemCode;
            }
            return 0;
        }

        public get target(): int
        {
            if (this._info) 
            {
                return this._info.target;
            }
            return 0;
        }

        public get day(): int
        {
            if (this._info) 
            {
                return this._info.value;
            }
            return 0;
        }

        protected /* override */ configUI(): void
        {
            this._bg = ObjCreate.createBitmap(null, 2, 2, this);
            this._dayBmp = ObjCreate.createBitmap(null, 19, 10, this);
            this._itemBg = ObjCreate.createBg(15, 30, 60, 60, this, ImagesConst.PackItemBg);
            this._item = new BaseItem();
            this._item.setSize(56, 56);
            this._item.move(17, 32);
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            addChild(this._item);
            this._getBtn = ObjCreate.createGButton("", 19, 100, 55, 25, this, GlobalSkin.ButtonRed);
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            if (this._info) 
            {
                this._dayBmp.bitmapData = GlobalClass.getBitmapData("openDay_" + this._info.value);
            }
            if (this._openRechageInfo.isOpenDay) 
            {
                this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.openDayCurBg);
            }
            else 
            {
                this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.openDayBg);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (arg1 && arg1 is OpenRechargeInfo) 
            {
                this._openRechageInfo = arg1 as OpenRechargeInfo;
                this._info = this._openRechageInfo.info;
                this._item.itemData = new ItemData(this._info.itemCode);
                this._getBtn.enabled = false;
                if (this._openRechageInfo.openState != OpenRechargeType.OpenRechargeTypeCanGet) 
                {
                    if (this._openRechageInfo.openState != OpenRechargeType.OpenRechargeTypeHadGot) 
                    {
                        if (this._openRechageInfo.openState != OpenRechargeType.OpenRechargeTypeHadOpen) 
                        {
                            if (this._openRechageInfo.openState != OpenRechargeType.OpenRechargeTypeNotOpen) 
                            {
                                if (this._openRechageInfo.openState == OpenRechargeType.OpenRechargeTypeOverdue) 
                                {
                                    this._getBtn.label = Language.getString(36666);
                                }
                            }
                            else 
                            {
                                this._getBtn.label = Language.getString(36665);
                            }
                        }
                        else 
                        {
                            this._getBtn.enabled = true;
                            this._getBtn.label = Language.getString(36664);
                        }
                    }
                    else 
                    {
                        this._getBtn.label = Language.getString(36663);
                    }
                }
                else 
                {
                    this._getBtn.enabled = true;
                    this._getBtn.label = Language.getString(36662);
                }
                LoaderHelp.addResCallBack(ResFileConst.OpenSevenRecharge, this.onResLoaded);
            }
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.OpenRechargeGetGiftBag, this._info.code));
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            if (arg1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.OpenRechargeGiftBagSelected, this._openRechageInfo));
                this._bg.filters = [FilterConst.gradientGlowFilter];
            }
            else 
            {
                this._bg.filters = [];
            }
            return;
        }

        /* internal */ /* var */_openRechageInfo: OpenRechargeInfo;

        /* internal */ /* var */_info: TOpenRechargeGiftBag;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_dayBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemBg: ScaleBitmap;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_getBtn: GButton;
    }
